package com.gewu.pm.utils.eventbus;

import org.greenrobot.eventbus.EventBus;

/**
 * EventBus
 * https://www.jianshu.com/p/199d8e376dd3
 */
public class EventBusUtil {
    /**
     * 订阅事件
     * @param subscriber
     */
    public static void register(Object subscriber) {
        EventBus.getDefault().register(subscriber);
    }

    /**
     * 取消订阅事件
     * @param subscriber
     */
    public static void unregister(Object subscriber) {
        //先检查一下
        if (EventBus.getDefault().isRegistered(subscriber)) {
            EventBus.getDefault().unregister(subscriber);
        }

    }

    /**
     * 发送消息
     * @param event
     */
    public static void sendEvent(EventBean event) {
        EventBus.getDefault().post(event);
    }

    /**
     * 发送粘性消息
     * @param event
     */
    public static void sendStickyEvent(EventBean event) {
        EventBus.getDefault().postSticky(event);
    }
}
